// pages/collect/collect.js
Page({

  data: {
    c1:true,
    c2:false,
    c3:false,
    collect:[]
  },
  onLoad(){
    var that = this;
    //初始展示物品收藏
    wx.request({
      url: 'http://127.0.0.1:8080/itemCollect/showItemCollect',
      method:"POST",
      data:{userid:wx.getStorageSync('openid')},
      success(res){
        if(res.data.length != 0){
          // console.log(res)
        for(var i=0;i<res.data.length;i++){
          res.data[i].itemPic = JSON.parse(res.data[i].itemPic)
        }
        that.setData({
          collect:res.data
        })
        }
        
      }
    })
  },
  /*选择收藏信息 */
  c1(){
    var that = this;
    //初始展示物品收藏
    wx.request({
      url: 'http://127.0.0.1:8080/itemCollect/showItemCollect',
      method:"POST",
      data:{userid:wx.getStorageSync('openid')},
      success(res){
        if(res.data.length != 0){
          // console.log(res)
        for(var i=0;i<res.data.length;i++){
          res.data[i].itemPic = JSON.parse(res.data[i].itemPic)
        }
        that.setData({
          collect:res.data
        })
        }
        
      }
    })
    this.setData({
      c1:true,
      c2:false,
      c3:false
    })
  },
  c2(){ 
    var that = this;
    //初始展示求租信息收藏
    wx.request({
      url: 'http://127.0.0.1:8080/helpCollect/showHelpCollect',
      method:"POST",
      data:{userid:wx.getStorageSync('openid')},
      success(res){
        if(res.data.length != 0){
          // console.log(res)
        for(var i=0;i<res.data.length;i++){
          res.data[i].itemPic = JSON.parse(res.data[i].helpPic)
          res.data[i].submitDate = res.data[i].helpTime.substring(0,10)
          res.data[i].itemTitle = res.data[i].helpText
        }
        that.setData({
          collect:res.data
        })
        }
        
      }
    })
    this.setData({
      c1:false,
      c2:true,
      c3:false
    })
  },
  c3(){
    // 展示收藏的租房信息
    var that = this;
    wx.request({
      url: 'http://127.0.0.1:8080/rentalCollect/showRentalCollect',
      method:"POST",
      data:{userid:wx.getStorageSync('openid')},
      success(res){
        if(res.data.length != 0){
          // console.log(res)
        for(var i=0;i<res.data.length;i++){
          res.data[i].itemPic = JSON.parse(res.data[i].rentalPic)
          res.data[i].submitDate = res.data[i].submitTime.substring(0,10)
          res.data[i].itemTitle = res.data[i].rentalTitle
        }
        that.setData({
          collect:res.data
        })
        }
        
      }
    })
    this.setData({
      c1:false,
      c2:false,
      c3:true
    })
  },

  choose(e){
    var index = e.currentTarget.dataset.index
    // console.log(index)
    if(this.data.c1 == true){
      wx.navigateTo({
        url: '/pages/iteminfo/iteminfo?itemid='+this.data.collect[index].itemIdForCollect,
      })
    }else if(this.data.c2 == true){
      wx.navigateTo({
        url: '/pages/helpdetail/helpdetail?helpinfoid='+this.data.collect[index].helpInfoIdForCollect,
      })
    }else{
      wx.navigateTo({
        url: '/pages/house/house?rentalid='+this.data.collect[index].rentalIdRentalCollect,
      })
    }

  }



})